'use strict';

module.exports = {
    up: async (queryInterface, Sequelize) => {
        const { STRING, INTEGER, BIGINT, DATE, BOOLEAN, NOW } = Sequelize;

        await queryInterface.createTable(
            'tbl_user_base',
            {
                id: {
                    type: INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                user_id: {
                    type: INTEGER,
                    allowNull: false,
                    unique: true
                },
                register_state: {
                    type: INTEGER,
                    allowNull: false
                },
                member_code: {
                    type: STRING(16),
                    allowNull: true
                },
                id_number: {
                    type: STRING(18),
                    allowNull: true
                },
                body_height: {
                    type: INTEGER,
                    allowNull: true
                },
                body_weight: {
                    type: INTEGER,
                    allowNull: true
                },
                stature_id: {
                    type: INTEGER,
                    allowNull: true
                },
                live_region: {
                    type: STRING(32),
                    allowNull: true
                },
                birth_region: {
                    type: STRING(32),
                    allowNull: true
                },
                marriage_state: {
                    type: INTEGER,
                    allowNull: true
                },
                child_state: {
                    type: INTEGER,
                    allowNull: true
                },
                nationality_id: {
                    type: INTEGER,
                    allowNull: true
                },
                month_pay: {
                    type: INTEGER,
                    allowNull: true
                },
                education_id: {
                    type: INTEGER,
                    allowNull: true
                },
                organization_id: {
                    type: INTEGER,
                    allowNull: true
                },
                vocation_id: {
                    type: INTEGER,
                    allowNull: true
                },
                university: {
                    type: STRING(32),
                    allowNull: true
                },
                major: {
                    type: STRING(32),
                    allowNull: true
                },
                house_state: {
                    type: INTEGER,
                    allowNull: true
                },
                loan_state: {
                    type: INTEGER,
                    allowNull: true
                },
                vehicle_state: {
                    type: INTEGER,
                    allowNull: true
                },
                smoke_state: {
                    type: INTEGER,
                    allowNull: true
                },
                drink_state: {
                    type: INTEGER,
                    allowNull: true
                },
                sport_state: {
                    type: INTEGER,
                    allowNull: true
                },
                marriage_plan: {
                    type: INTEGER,
                    allowNull: true
                },
                child_plan: {
                    type: INTEGER,
                    allowNull: true
                },
                introduction: {
                    type: STRING,
                    allowNull: true
                },
                avatar_verify: {
                    type: INTEGER,
                    allowNull: true
                },
                identity_verify: {
                    type: INTEGER,
                    allowNull: true
                },
                education_verify: {
                    type: INTEGER,
                    allowNull: true
                },
                single_state: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                complaint_state: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                bonus_points: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 0
                },
                online: {
                    type: BOOLEAN,
                    allowNull: false,
                    defaultValue: false
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });

        await queryInterface.createTable(
            'tbl_user_photo',
            {
                id: {
                    type: INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 0
                },
                state: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                user_id: {
                    type: INTEGER,
                    allowNull: false
                },
                image: {
                    type: STRING(128),
                    allowNull: true
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });

        await queryInterface.createTable(
            'tbl_member_relation',
            {
                id: {
                    type: INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 0
                },
                state: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                user_id: {
                    type: INTEGER,
                    allowNull: false
                },
                target_user_id: {
                    type: INTEGER,
                    allowNull: false
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });

        await queryInterface.createTable(
            'tbl_member_couple',
            {
                id: {
                    type: INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 0
                },
                state: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                user_id: {
                    type: INTEGER,
                    allowNull: false
                },
                target_user_id: {
                    type: INTEGER,
                    allowNull: false
                },
                invite_note: {
                    type: STRING,
                    allowNull: true
                },
                reject_note: {
                    type: STRING,
                    allowNull: true
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });

        await queryInterface.createTable(
            'tbl_member_message',
            {
                id: {
                    type: BIGINT,
                    primaryKey: true,
                    autoIncrement: true
                },
                type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 0
                },
                state: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                user_id: {
                    type: INTEGER,
                    allowNull: false
                },
                target_user_id: {
                    type: INTEGER,
                    allowNull: false
                },
                user_state: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                target_user_state: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                content: {
                    type: STRING,
                    allowNull: true
                },
                image: {
                    type: STRING(128),
                    allowNull: true
                },
                read_state: {
                    type: BOOLEAN,
                    allowNull: false,
                    defaultValue: 1
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });

        await queryInterface.createTable(
            'tbl_member_show',
            {
                id: {
                    type: INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 0
                },
                state: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                user_id: {
                    type: INTEGER,
                    allowNull: false
                },
                content: {
                    type: STRING,
                    allowNull: true
                },
                image: {
                    type: STRING(128),
                    allowNull: true
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });

        await queryInterface.createTable(
            'tbl_member_comment',
            {
                id: {
                    type: INTEGER,
                    primaryKey: true,
                    autoIncrement: true
                },
                type: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 0
                },
                state: {
                    type: INTEGER,
                    allowNull: false,
                    defaultValue: 1
                },
                user_id: {
                    type: INTEGER,
                    allowNull: false
                },
                target_user_id: {
                    type: INTEGER,
                    allowNull: false
                },
                module_id: {
                    type: INTEGER,
                    allowNull: true
                },
                content: {
                    type: STRING,
                    allowNull: true
                },
                created_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                },
                updated_at: {
                    type: DATE,
                    allowNull: false,
                    defaultValue: NOW
                }
            },
            {
                charset: 'utf8'
            });
    },

    down: async (queryInterface, Sequelize) => {
        // await queryInterface.dropTable('tbl_user_base');
        // await queryInterface.dropTable('tbl_user_photo');
        // await queryInterface.dropTable('tbl_member_relation');
        // await queryInterface.dropTable('tbl_member_couple');
        // await queryInterface.dropTable('tbl_member_message');
        // await queryInterface.dropTable('tbl_member_show');
        // await queryInterface.dropTable('tbl_member_comment');
    }
};
